import 'dart:math';

import 'package:flutter/material.dart';
import 'package:order/generated/assets.dart';
import 'package:order/order_dish_item.dart';
import 'package:wave/config.dart';
import 'package:wave/wave.dart';
import 'dart:math' as math;

import '../constant/app_colors.dart';
import '../constant/data.dart';

class DeskPage extends StatefulWidget {
  const DeskPage({super.key});

  @override
  State<DeskPage> createState() => _DeskPageState();
}

class _DeskPageState extends State<DeskPage> {
  @override
  Widget build(BuildContext context) {
    double screenHeight = MediaQuery.of(context).size.height;
    double tableWidth = 350;

    dynamic data = dishData;
    dynamic tableHead = {
      "num":"项",
      "dishName": "品名",
      "dishCount": "数量",
      "dishValue": "金额"
    };

    return SizedBox(
      height: double.infinity,
      width: double.infinity,
      child: Row(
        children: [
          Container(
            margin:
                const EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
            padding:
                const EdgeInsets.only(left: 20, right: 20, top: 10, bottom: 10),
            height: double.infinity,
            width: tableWidth,
            decoration: BoxDecoration(
              color: AppColors.bgWhite,
              borderRadius: BorderRadius.circular(10),
            ),
            child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  const SizedBox(
                    height: 25,
                  ),
                  const Text(
                    "订单",
                    style: TextStyle(
                        color: AppColors.fontGrey3,
                        fontSize: 18,
                        fontWeight: FontWeight.w600),
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        "来源  ${dishData["from"]} ",
                        style: const TextStyle(
                            color: AppColors.fontGrey3, fontSize: 15),
                      ),
                      Row(
                        children: [
                          const Text(
                            "no  ",
                            style: TextStyle(
                                color: AppColors.fontGrey5, fontSize: 16),
                          ),
                          Text(
                            dishData["no"],
                            style: const TextStyle(
                                color: AppColors.fontRed, fontSize: 16),
                          ),
                        ],
                      )
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        "桌号 ${dishData["deskNum"]}",
                        style: const TextStyle(
                            color: AppColors.fontGrey3, fontSize: 15),
                      ),
                      Text(
                        "人数 ${dishData["personCount"]}",
                        style: const TextStyle(
                            color: AppColors.fontGrey3, fontSize: 15),
                      ),
                      Text(
                        dishData["createDate"],
                        style: const TextStyle(
                            color: AppColors.fontGrey3, fontSize: 12),
                      ),
                    ],
                  ),
                  //表单
                  const SizedBox(
                    height: 10,
                  ),
                  Container(
                    height: screenHeight - 350,
                    decoration: const BoxDecoration(
                        border: Border(
                      top: BorderSide(color: AppColors.fontGrey3, width: 1),
                      right: BorderSide(color: AppColors.fontGrey3, width: 1),
                      bottom: BorderSide(color: AppColors.fontGrey3, width: 1),
                      left: BorderSide(color: AppColors.fontGrey3, width: 1),
                    )),
                    child: Stack(
                      children: [
                    /*    Container(
                         height: 25,
                          decoration: const BoxDecoration(
                            border: Border(
                              bottom: BorderSide(color: AppColors.fontGrey3,width: 1),
                            )
                          ),
                          child: const Row(
                            children: [
                              Text("123")
                            ],
                          ),

                        ),*/

                        OrderDishItem(itemData: tableHead,),

                        Positioned(
                         bottom: 0,
                          child: Container(
                            padding: const EdgeInsets.only(left: 8,right: 80),
                            height: 35,
                            width: tableWidth,
                            decoration: const BoxDecoration(
                                border: Border(
                              top: BorderSide(
                                  color: AppColors.fontGrey3, width: 1),
                            )),
                            child: const Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  "应收(实收)",
                                  style: TextStyle(
                                      color: AppColors.fontGrey3, fontSize: 14),
                                ),

                                Text(
                                  "¥270000",
                                  style: TextStyle(
                                      color: AppColors.fontRed, fontSize: 14),
                                ),

                              ],
                            ),
                          ),
                        )
                      ],
                    ),
                  ),

                  Table(
                    border: const TableBorder(
                      left: BorderSide(color: AppColors.fontGrey3, width: 2),
                      right: BorderSide(color: AppColors.fontGrey3, width: 2),
                      bottom: BorderSide(color: AppColors.fontGrey3, width: 2),
                      horizontalInside:
                          BorderSide(color: AppColors.fontGrey3, width: 2),
                      verticalInside:
                          BorderSide(color: AppColors.fontGrey3, width: 2),
                    ),
                    defaultVerticalAlignment: TableCellVerticalAlignment.middle,
                    children: const [
                      TableRow(children: [
                        SizedBox(
                          height: 50,
                          child: Center(
                            child: Text("项"),
                          ),
                        ),
                      ]),
                    ],
                  ),
                ]),
          )
        ],
      ),
    );
  }
}



class CurvedBackgroundPainter extends CustomPainter {
  final Paint _paint = Paint()..color = Colors.blue;
  double _waveHeight = 0.0;
  double _waveWidth = 0.0;

  @override
  void paint(Canvas canvas, Size size) {
    _waveHeight = size.height * 0.15;
    _waveWidth = size.width * 0.9;

    var path = Path();
    path.moveTo(0, size.height - _waveHeight);

    for (var x = 0.0; x < size.width * 1.5; x += _waveWidth) {
      var y = size.height -
          _waveHeight * 2.0 * (1 + sin((x + 2 * pi * 2) / (_waveWidth * 4)));
      path.lineTo(x, y);
    }

    path.lineTo(size.width, size.height);
    path.lineTo(0, size.height);
    path.close();

    canvas.drawPath(path, _paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }
}
